package com.liang.rabbitmqspringbootconsumer.service.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Configuration
public class ttlRabbitMqConfiguration {
//: 声明注册direct模式的交换机

    @Bean
    public DirectExchange ttlDirectExchange(){
        return new DirectExchange("ttl_direct_exchange",true,false);
    }

    // 2: 声明队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
    @Bean
    public Queue smsQueuettlDirect(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", 5000);//int类型
        return new Queue("ttl.direct.queue",true,false,false,args);
    }

    @Bean
    public Binding emailBingdingDirectTTL(){
        return BindingBuilder.bind(ttlDirectExchange()).to(ttlDirectExchange()).with("ttl");
    }


}
